const {DataTypes} = require('sequelize')

const sequelize = require('../db/sequelize')

//创建模型  模型对应数据表
const Dictionary = sequelize.define('Dictionary', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        allowNull: false,
        autoIncrement: true,
        comment: 'id'
    },
    pid: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: 'pid'
    },
    path: {
        type: DataTypes.TEXT(100),
        allowNull: true,
        comment: '路径'
    },
    type: {
        type: DataTypes.TEXT(100),
        allowNull: false,
        comment: 'type 字典类型'
    },
    level: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: '层级'
    },
    code: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '字典值'
    },
    name: {
        type: DataTypes.TEXT(100),
        allowNull: false,
        comment: '字典名'
    },
    remark: {
        type: DataTypes.TEXT(200),
        allowNull: true,
        comment: '备注',
    },
    children: {
        type: DataTypes.VIRTUAL,
        get(){return null;}
    }
}, {
    tableName: 'dictionary',
    timestamps: true
})

//强制同步数据库（创建数据表）
Dictionary.sync()

module.exports = Dictionary